#!/usr/bin/env node

// Node CLI 应用入口文件必须要有这样的文件夹
// 如果是 Linux / macOS 系统下还需要修改此文件的读写权限 755
// 具体通过 chmod 755 cli.js 实现修改

const path = require('path')
const inquirer = require('inquirer')
const fs = require('fs')
const ejs = require('ejs')
const { join } = require('path')

inquirer.prompt([
    {
        type:'input',
        name:'name',
        message:'project name ?'
    },
    {
        type:'input',
        name:'age',
        message:'project name ?'
    }
])
.then(anwsers => {
    const tmplDir = path.join(__dirname,'templates')
    const destDir = process.cwd()
    fs.readdir(tmplDir,(err,files) => {
        if(err) throw err
        files.forEach(element => {
            ejs.renderFile(path.join(tmplDir,element),anwsers,(err,result) => {
                if (err) throw err
                fs.writeFileSync(path.join(destDir,element),result)
            })

        });

    })
})


